package com.working.libbase.model

import android.text.Html
import com.squareup.moshi.JsonClass
import com.working.libcommon.adapter.IPagingKey


@JsonClass(generateAdapter = true)
data class ArticleResponse(
    val apkLink: String,
    val audit: Int,
    val author: String?,
    val canEdit: Boolean,
    val chapterId: Int,
    val chapterName: String,
    val collect: Boolean,
    val courseId: Int,
    val desc: String,
    val descMd: String,
    val envelopePic: String,
    val fresh: Boolean,
    val host: String,
    val id: Int,
    val link: String,
    val niceDate: String,
    val niceShareDate: String,
    val origin: String,
    val prefix: String,
    val projectLink: String,
    val publishTime: Long,
    val realSuperChapterId: Int,
    val selfVisible: Int,
    val shareDate: Long?,
    val shareUser: String,
    val superChapterId: Int,
    val superChapterName: String,
    val tags: List<ArticleTag>,
    val title: String,
    val type: Int,
    val userId: Int,
    val visible: Int,
    val zan: Int,
    var top: Boolean = false
) : IPagingKey {
    override fun getKey() = id

    fun titleImpl() = Html.fromHtml(title).toString()

    fun descImpl() = Html.fromHtml(desc).toString()

    fun authorImpl() = author.takeIf { it.isNullOrBlank().not() } ?: shareUser

    fun tagImpl() = tags.firstOrNull()?.name
}

@JsonClass(generateAdapter = true)
data class ArticleTag(
    val name: String,
    val url: String
)

@JsonClass(generateAdapter = true)
data class BannerResponse(
    val desc: String?,
    val id: Int?,
    val imagePath: String?,
    val isVisible: Int?,
    val order: Int?,
    val title: String?,
    val type: Int?,
    val url: String?
)

@JsonClass(generateAdapter = true)
data class HotSearchResponse(
    val id: Int,
    val link: String,
    val name: String,
    val order: Int,
    val visible: Int
)

@JsonClass(generateAdapter = true)
data class ProjectTreeResponse(
    val children: List<Any>,
    val courseId: Int,
    val id: Int,
    val name: String,
    val order: Int,
    val parentChapterId: Int,
    val visible: Int
) {
    fun nameImpl() = Html.fromHtml(name)
}
